package com.imageim.yimirror.ui.fragment;

import android.graphics.Bitmap;
import android.text.TextUtils;

import com.imageim.yimirror.R;
import com.imageim.yimirror.base.BaseFragment;
import com.imageim.yimirror.base.Constants;
import com.imageim.yimirror.bean.analysisPhoto.PhotoNoBean;
import com.imageim.yimirror.common.ui.analysis.AnalysisPhotoView2;
import com.imageim.yimirror.common.util.UserUtil;
import com.martin.ads.omoshiroilib.util.BitmapUtils;

import butterknife.BindView;

/**
 * Created by Yuaihen.
 * on 2018/11/29
 * 身线图Fragment
 */
public class BodyLineFragment extends BaseFragment {

    private static final String TAG = "BodyLineFragment";

    @BindView(R.id.panel_analysis_photo)
    AnalysisPhotoView2 analysisPhotoView;
    private Bitmap mBitmap;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_body_line;
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        setDataToBodyView();
    }

    /**
     * 设置拍照时保存的数据到BodyView里面
     */
    private void setDataToBodyView() {
        //显示裁剪后的Bitmap
        String clipBitmap = UserUtil.getClipBitmap();
        if (!TextUtils.isEmpty(clipBitmap)) {
            analysisPhotoView.show();
            mBitmap = BitmapUtils.base64ToBitmap(clipBitmap);
            analysisPhotoView.setPhoto(mBitmap);
        }

        //根据性别设置对应身体部位图标
        //        int gender = UserUtil.getGender();
        //        analysisPhotoView.setBodyPartImgs(gender);

        PhotoNoBean photoNoBean = UserUtil.getBeanByGson(Constants.BODY_LINE_PARAM, PhotoNoBean.class);
        analysisPhotoView.setBodyData(photoNoBean);

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (analysisPhotoView != null) {
            analysisPhotoView.destory();
        }

        if (mBitmap != null) {
            mBitmap.recycle();
        }
    }

//    @Override
//    public void onHiddenChanged(boolean hidden) {
//        super.onHiddenChanged(hidden);
//        if (hidden) {
//            hideBodyLine();
//        } else {
//            showBodyLine();
//        }
//    }

    public void hideBodyLine() {
        if (analysisPhotoView != null) {
            analysisPhotoView.hideBodyLine();
        }
    }

    public void showBodyLine() {
        if (analysisPhotoView != null) {
            analysisPhotoView.showBodyLine();
        }
    }

}
